<template>
  <div>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col  :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="订单日期">
              <j-date placeholder="开始日期" v-model="queryParam.orderDateBegin" class="query-group-cust"/>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="截至日期" v-model="queryParam.orderDateEnd" class="query-group-cust"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="供应商">
              <j-search-select-tag placeholder="请输入供应商" v-model="queryParam.supplyId"
                                   dict="mdm_supply,supply_full_name,id"/>
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料描述">
              <a-input placeholder="请输入物料描述" v-model="queryParam.materialDesc"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
                  <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                    <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                    <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                  </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="j-table-force-nowrap"
      :scroll="{x:true}"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange">

      <template slot="htmlSlot" slot-scope="text">
        <div v-html="text"></div>
      </template>
      <template slot="imgSlot" slot-scope="text">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
        <img v-else :src="getImgView(text)" height="25px" alt=""
             style="max-width:80px;font-size: 12px;font-style: italic;"/>
      </template>
      <template slot="fileSlot" slot-scope="text">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
        <a-button
          v-else
          :ghost="true"
          type="primary"
          icon="download"
          size="small"
          @click="downloadFile(text)">
          下载
        </a-button>
      </template>
      <template slot="materialDesc" slot-scope="text, record">
        <j-ellipsis :value="text" :length="18"/>
      </template>
      <template slot="materialNo" slot-scope="text, record">
        <j-ellipsis :value="text" :length="12"/>
      </template>
      <template slot="footer" slot-scope="currentPageData" >
        <div text-align="right">
          合计： 采购金额&nbsp;&nbsp;<span style="font-size:16px;color: rgba(0, 0, 0, 0.65)">¥{{totalPurPrice}}</span> &nbsp;&nbsp; &nbsp; 退货金额&nbsp;&nbsp;<span style="font-size:16px;color: rgba(0, 0, 0, 0.65)">¥{{totalBackPrice}}</span>
        </div>
      </template>
    </a-table>
  </div>
</template>

<script>

import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import '@/assets/less/TableExpand.less'
import {getAction} from "@/api/manage";

export default {
  name: "MmRptPurOrderStatMaterial",
  mixins: [JeecgListMixin],
  components: {},
  data() {
    return {
      description: '采购统计报表-物料',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '物料编号',
          align: "center",
          width: 130,
          dataIndex: 'materialNo',
          scopedSlots: {customRender: 'materialNo'}
        },
        {
          title: '物料描述',
          align: "center",
          dataIndex: 'materialDesc',
          scopedSlots: {customRender: 'materialDesc'},
        },
        {
          title: '物料分类',
          align: "center",
          dataIndex: 'materialTypeName',
        },
        {
          title: '单位',
          align: "center",
          dataIndex: 'unit_dictText',
        },
        {
          title: '采购数量',
          align: "center",
          dataIndex: 'sumPurQty',
        },
        {
          title: '采购金额',
          align: "center",
          dataIndex: 'sumPurPrice',
        },
        {
          title: '退货数量',
          align: "center",
          dataIndex: 'sumBackQty',
        },
        {
          title: '退货金额',
          align: "center",
          dataIndex: 'sumBackPrice',
        },
      ],
      url: {
        list: "/mm/purchaseOrder/rptMaterialStatList",
        total: "/mm/purchaseOrder/rptMaterialStatTotal"
      },
      totalPurPrice: 0,
      totalBackPrice: 0,
    }
  },
  created() {

  },
  computed: {},
  methods: {
    loadData(arg) {
      if(!this.url.list){
        this.$message.error("请设置url.list属性!")
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
      var params = this.getQueryParams();//查询条件
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records||res.result;
          if(res.result.total)
          {
            this.ipagination.total = res.result.total;
          }else{
            this.ipagination.total = 0;
          }
        }else{
          this.$message.warning(res.message)
        }
      }).then(()=>{
        // 列合计
        getAction(this.url.total, params).then((res) => {
          if (res.success) {
            let totalData = res.result.records||res.result;
            this.totalPurPrice = totalData.totalPurPrice;
            this.totalBackPrice = totalData.totalBackPrice;
          }else{
            this.totalPurPrice = 0;
            this.totalBackPrice = 0;
            this.$message.warning(res.message)
          }
        })
      }).finally(() => {
        this.loading = false
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>